<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <title>新闻管理系统 - 登录</title>
    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">
    <!-- Font Awesome CDN -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
    <!-- Font Awesome 本地备份 -->
    <link rel="stylesheet" href="css/fontawesome.min.css">
    <link rel="stylesheet" href="font/fa-solid-900.ttf">
    <link rel="stylesheet" href="font/fa-regular-400.ttf">
    <!-- 自定义CSS -->
    <link rel="stylesheet" href="css/style.css">
    <!-- jQuery -->
    <script src="js/jquery.min.js" async></script>
    <!-- Bootstrap JS -->
    <script src="bootstrap/js/bootstrap.min.js" async></script>
</head>
<body class="bg-light">
    <!-- 消息提示框 -->
    <c:if test="${not empty sessionScope.message}">
        <div class="message-popup" id="messagePopup">
            <div class="message-content">
                ${sessionScope.message}
            </div>
        </div>
        <% session.removeAttribute("message"); %>
        <script>
            // 显示消息提示
            window.onload = function() {
                var popup = document.getElementById('messagePopup');
                popup.style.display = 'block';
                
                // 3秒后自动消失
                setTimeout(function() {
                    popup.style.opacity = '0';
                    setTimeout(function() {
                        popup.style.display = 'none';
                    }, 500);
                }, 3000);
            };
        </script>
    </c:if>

    <div class="container">
        <div class="row justify-content-center mt-5">
            <div class="col-md-6 col-lg-4">
                <div class="card shadow-lg">
                    <div class="card-body p-5">
                        <div class="text-center mb-4">
                            <i class="fas fa-newspaper fa-3x text-danger mb-3"></i>
                            <h2 class="text-danger">新闻管理系统</h2>
                        </div>
                        
                        <form id="loginForm" action="login" method="post">
                            <div class="form-group mb-3">
                                <label for="username" class="form-label">
                                    <i class="fas fa-user me-2"></i>用户名
                                </label>
                                <div class="input-group">
                                    <span class="input-group-text">
                                        <i class="fas fa-user"></i>
                                    </span>
                                    <input type="text" class="form-control" id="username" name="username" required>
                                    <div class="invalid-feedback">请输入用户名</div>
                                </div>
                            </div>
                            
                            <div class="form-group mb-4">
                                <label for="password" class="form-label">
                                    <i class="fas fa-lock me-2"></i>密码
                                </label>
                                <div class="input-group">
                                    <span class="input-group-text">
                                        <i class="fas fa-lock"></i>
                                    </span>
                                    <input type="password" class="form-control" id="password" name="password" required>
                                    <button class="btn btn-outline-secondary" type="button" id="togglePassword">
                                        <i class="fas fa-eye"></i>
                                    </button>
                                    <div class="invalid-feedback">请输入密码</div>
                                </div>
                            </div>
                            
                            <button type="submit" class="btn btn-danger w-100 mb-3">
                                <i class="fas fa-sign-in-alt me-2"></i>登录
                            </button>
                        </form>

                        <div class="text-center">
                            <a href="register.jsp" class="text-decoration-none me-3">
                                <i class="fas fa-user-plus"></i> 注册账号
                            </a>
                            <a href="forgot-password.jsp" class="text-decoration-none">
                                <i class="fas fa-key"></i> 忘记密码
                            </a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>


    <!-- 自定义JS -->
    <script>
        $(document).ready(function() {
            // 表单验证
            $('#loginForm').on('submit', function(e) {
                let isValid = true;
                
                // 验证用户名
                if ($('#username').val().trim() === '') {
                    $('#username').addClass('is-invalid');
                    isValid = false;
                } else {
                    $('#username').removeClass('is-invalid');
                }
                
                // 验证密码
                if ($('#password').val().trim() === '') {
                    $('#password').addClass('is-invalid');
                    isValid = false;
                } else {
                    $('#password').removeClass('is-invalid');
                }
                
                if (!isValid) {
                    e.preventDefault();
                }
            });
            
            // 输入框获得焦点时移除错误提示
            $('.form-control').on('focus', function() {
                $(this).removeClass('is-invalid');
            });

            // 密码显示切换
            $('#togglePassword').on('click', function() {
                const passwordInput = $('#password');
                const icon = $(this).find('i');
                
                if (passwordInput.attr('type') === 'password') {
                    passwordInput.attr('type', 'text');
                    icon.removeClass('fa-eye').addClass('fa-eye-slash');
                } else {
                    passwordInput.attr('type', 'password');
                    icon.removeClass('fa-eye-slash').addClass('fa-eye');
                }
            });
        });
    </script>
</body>
</html> 